package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description:自动化测试博客系统编辑页面
 * Author: WJW
 * Date: 2024-10-13
 * Time: 14:10
 */
public class EditPage extends Utils {
    public static String url = "http://8.137.19.140:9090/blog_edit.html";
    public EditPage() {
        super(url);
    }

    public void EditSuc() throws InterruptedException {
        String blogTile = "博客登录页面测试";
        driver.findElement(By.cssSelector("#title")).sendKeys(blogTile);
        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(1000);
      // WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));

        //无法输入博客内容怎么办？
        //法一：博客本身就有内容，我们不需要手动实现
        //法二：通过鼠标操作来实现
       /* 1.鼠标先挪动到博客内容区域
        2.双击鼠标将内容删掉：鼠标双击内容+键盘DELETE
        3.输入内容*/

       /* WebElement ele = driver.findElement(By.cssSelector("#editor > div.CodeMirror.cm-s-default.CodeMirror-wrap > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre"));
        Actions actions = new Actions(driver);
        Thread.sleep(3000);
        //perform作用：为了在页面看到效果
        //双击鼠标
        actions.doubleClick(ele).perform();
        Thread.sleep(3000);
        //删除
        actions.keyDown(Keys.DELETE).perform();
        Thread.sleep(3000);
        //输入内容
        actions.moveToElement(ele).sendKeys("键盘鼠标操作输入内容").perform();
        Thread.sleep(3000);*/


       //  通过检查博客辩题检查一下博客发布之后是否成功
//        String blogtitle = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(1874) > div.title")).getText();
//        assert blogtitle.equals(blogTile);

        //通过页面标题来检查是否发布成功
//        String title = driver.getTitle();
//        assert title.equals("博客列表页");

        //通过url来检查是否发布成功
        String url = driver.getCurrentUrl();
        assert url.equals("http://8.137.19.140:9090/blog_list.html");


    }
}
